import axios, { AxiosRequestConfig } from 'axios'

import {
  IAddEventTemplateReq,
  IEventTemplateDetailReq,
  IEventTemplateODTO,
  IEventTemplateReq,
  IEventTemplateRes,
  IEventTemplateTabCountRes,
  IUpdateEventTemplateReq,
} from '../interface'
import './__mock__'

/** 获取轨迹事件模板列表 */
export const apiGetEventTemplateList = async (
  req: IEventTemplateReq,
  signal?: AxiosRequestConfig['signal'],
): Promise<IEventTemplateRes> => {
  return axios.post(`/tmsapi/event_template/list`, { ...req }, { signal }).then(res => ({
    ...res.$data,
  }))
}

/** 新增轨迹事件模板 */
export const apiAddEventTemplate = async (
  req: IAddEventTemplateReq,
  signal?: AxiosRequestConfig['signal'],
): Promise<IEventTemplateRes> => {
  return axios.post(`/tmsapi/event_template/add`, { ...req }, { signal }).then(res => ({
    ...res.$data,
  }))
}

/** 更新轨迹事件模板 */
export const apiUpdateEventTemplate = async (
  req: IUpdateEventTemplateReq,
  signal?: AxiosRequestConfig['signal'],
): Promise<IEventTemplateRes> => {
  return axios.post(`/tmsapi/event_template/update`, { ...req }, { signal }).then(res => ({
    ...res.$data,
  }))
}

/** 获取轨迹事件模板详情 */
export const apiGetEventTemplateDetail = async (
  req: IEventTemplateDetailReq,
  signal?: AxiosRequestConfig['signal'],
): Promise<IEventTemplateODTO> => {
  return axios.post(`/tmsapi/event_template/get`, { ...req }, { signal }).then(res => ({
    ...res.$data,
  }))
}

// 获取轨迹事件模板标签数量
export const apiGetEventTemplateTabCount = async (
  req: IEventTemplateReq,
  signal?: AxiosRequestConfig['signal'],
): Promise<IEventTemplateTabCountRes[]> => {
  return axios.post(`/tmsapi/event_template/tab/count`, { ...req }, { signal }).then(res => res.$data)
}
